package com.macbulldev.poc.testgin.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;


import org.apache.log4j.Logger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.macbulldev.poc.testgin.service.WebappUtils;



@org.springframework.stereotype.Controller
public class AdminController {
	private static final Logger LOGGER = Logger.getLogger(AdminController.class);

//	@Autowired
//	@Qualifier("schedulerFactory")
//	private SchedulerFactoryBean schedulerFactory;

	@RequestMapping(value = "/admin/schedule/import/form",method = RequestMethod.GET)    
    public String create( ModelMap modelMap) {         
        return "admin/schedule_form";
    }
	
	@RequestMapping(value = "/admin/schedule/import",method = RequestMethod.POST)    
    public String scheduleImport(@RequestParam("path") String importPath,HttpSession session, ModelMap modelMap) throws SchedulerException {         
		LOGGER.error("importing"); 
		
		return "redirect:/admin/schedule/list";
    }

	@RequestMapping(value = "/admin/schedule/list",method = RequestMethod.GET)    
    public String scheduleImport( Model model) throws SchedulerException 
	{      
//		  Scheduler sched = schedulerFactory.getScheduler();
//
//		  
//		     List<JobExecutionContext> jobs = sched.getCurrentlyExecutingJobs();
////		     
////		     for (JobExecutionContext jec: jobs)
////		     {
////		    	 LOGGER.debug("Job Name:"+jec.getJobDetail().getName());
////		    	 LOGGER.debug("Job Run Time:"+jec.getJobRunTime());
////		    	 LOGGER.debug("Next Fire Time:"+jec.getNextFireTime()); 
////
////		     }
//	         model.addAttribute("jobList", jobs);
//	 
//	 
        return "admin/schedule_list";
    }

//	public SchedulerFactoryBean getSchedulerFactory() {
//		return schedulerFactory;
//	}
//
//	public void setSchedulerFactory(SchedulerFactoryBean schedulerFactory) {
//		this.schedulerFactory = schedulerFactory;
//	}
	
	
	
	
}
